package com.ruoyi.web.controller.ddsystem;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DdUserDiscount;
import com.ruoyi.system.service.IDdUserDiscountService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户优惠卷Controller
 * 
 * @author ruoyi
 * @date 2020-04-12
 */
@Controller
@RequestMapping("/system/discount_user")
public class DdUserDiscountController extends BaseController
{
    private String prefix = "system/discount_user";

    @Autowired
    private IDdUserDiscountService ddUserDiscountService;

    @RequiresPermissions("system:discount_user:view")
    @GetMapping()
    public String discount_user(String userid,Model m)
    {
        m.addAttribute("userid",userid);
        return prefix + "/discount_user";
    }

    /**
     * 查询用户优惠卷列表
     */
    @RequiresPermissions("system:discount_user:list")
    @PostMapping("/list/")
    @ResponseBody
    public TableDataInfo list(DdUserDiscount ddUserDiscount)
    {
        startPage();
        List<DdUserDiscount> list = ddUserDiscountService.selectDdUserDiscountList(ddUserDiscount);
        return getDataTable(list);
    }

    /**
     * 导出用户优惠卷列表
     */
    @RequiresPermissions("system:discount_user:export")
    @Log(title = "用户优惠卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DdUserDiscount ddUserDiscount)
    {
        List<DdUserDiscount> list = ddUserDiscountService.selectDdUserDiscountList(ddUserDiscount);
        ExcelUtil<DdUserDiscount> util = new ExcelUtil<DdUserDiscount>(DdUserDiscount.class);
        return util.exportExcel(list, "discount_user");
    }

    /**
     * 新增用户优惠卷
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户优惠卷
     */
    @RequiresPermissions("system:discount_user:add")
    @Log(title = "用户优惠卷", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DdUserDiscount ddUserDiscount)
    {
        return toAjax(ddUserDiscountService.insertDdUserDiscount(ddUserDiscount));
    }

    /**
     * 修改用户优惠卷
     */
    @GetMapping("/edit/{uuid}")
    public String edit(@PathVariable("uuid") String uuid, ModelMap mmap)
    {
        DdUserDiscount ddUserDiscount = ddUserDiscountService.selectDdUserDiscountById(uuid);
        mmap.put("ddUserDiscount", ddUserDiscount);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户优惠卷
     */
    @RequiresPermissions("system:discount_user:edit")
    @Log(title = "用户优惠卷", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DdUserDiscount ddUserDiscount)
    {
        return toAjax(ddUserDiscountService.updateDdUserDiscount(ddUserDiscount));
    }

    /**
     * 删除用户优惠卷
     */
    @RequiresPermissions("system:discount_user:remove")
    @Log(title = "用户优惠卷", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ddUserDiscountService.deleteDdUserDiscountByIds(ids));
    }
}
